package cn.gjculture.shopping.api.service.impl;

import cn.gjculture.shopping.api.dao.ArtistDao;
import cn.gjculture.shopping.api.dao.CommonDeleteMapper;
import cn.gjculture.shopping.api.dao.CommonUpdateMapper;
import cn.gjculture.shopping.api.entity.Artist;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.ArtistService;
import cn.gjculture.shopping.api.util.DateUtil;
import cn.gjculture.shopping.api.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArtistServiceImpl implements ArtistService {

    @Autowired
    ArtistDao artistDao;

    @Autowired
    CommonDeleteMapper commonDeleteMapper;

    @Autowired
    CommonUpdateMapper commonUpdateMapper;

    @Override
    public int insert(Artist artist) {
        artist.setArtistId(UUIDUtil.getUUID());
        artist.setInsertTime(DateUtil.getTimestamp());
        artist.setUpdateTime(DateUtil.getTimestamp());
        return artistDao.insert(artist);
    }

    @Override
    public int update(Artist artist) {
        artist.setUpdateTime(DateUtil.getTimestamp());
        return commonUpdateMapper.updateArtist(artist);
    }

    @Override
    public List<Artist> query() {
        return artistDao.query();
    }

    @Override
    public Artist queryById(String artistId) {
        return artistDao.queryById(artistId);
    }

    public int delete(String id, Return ret){
        if(artistDao.queryCountArtById(id)>0){
            ret.getCommon().setMessage("艺术家下面有艺术品，不能删除");
            return 0;
        }
        return artistDao.delete(id);
    }
}
